/**
 * CRM控制器
 */
package com.kerrykidz.filemanagement.controller;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.kerrykidz.common.Constants;
import com.kerrykidz.common.service.ICommonService;
import com.kerrykidz.filemanagement.service.ICrmService;
import com.kerrykidz.filemanagement.service.ISalesService;
import com.kerrykidz.filemanagement.service.IVipService;
import com.kerrykidz.filemanagement.vo.CrmVO;
import com.kerrykidz.membership.service.IGuaService;
import com.kerrykidz.membership.service.IMemberService;
import com.kerrykidz.system.dao.model.GblSecBranEntity;
import com.kerrykidz.system.service.IGblService;
import com.kerrykidz.system.util.UserUtil;
import com.kerrykidz.system.vo.UserInfo;
import com.rdp.framework.exception.RDPException;

/**
 * @author Tik
 * 
 */
@RequestMapping("crm")
@Controller
public class CrmController {

	@Autowired
	private ICrmService crmService;
	@Autowired
	private ICommonService commonService;
	@Autowired
	private IMemberService memberService;
	@Autowired
	private IGuaService guaService;
	@Autowired
	private IVipService vipService;
	@Autowired
	private ISalesService salesService;
	@Autowired
	private IGblService gblService;


	/**
	 * 跳转到访客界面
	 * 
	 * @return
	 * @throws RDPException 
	 */
	@RequestMapping("/jumpCrm")
	public ModelAndView jumpCrm(HttpSession session) throws RDPException {
		ModelAndView mv = new ModelAndView("file/file_crm");
		List<GblSecBranEntity> branchs = new ArrayList<GblSecBranEntity>();
		UserInfo ui = UserUtil.getUserFromSession();
		if ("ZB".equals(ui.getAbbrCode())) {
			branchs = commonService.findBranSearchList();
			GblSecBranEntity bran = new GblSecBranEntity();
			bran.setPkBranId("");
			bran.setBranName("全部");
			branchs.add(0, bran);
		} else {
			GblSecBranEntity bran = new GblSecBranEntity();
			bran.setPkBranId(ui.getBranId());
			bran.setBranName(ui.getBranName());
			branchs.add(bran);
		}
		mv.addObject("branchs", branchs);
		
		return mv;
	}

	/**
	 * 查询会员活跃度信息
	 * 
	 * @return
	 * @throws RDPException
	 */
	@RequestMapping("/searchLiveness")
	@ResponseBody
	public CrmVO searchLiveness(CrmVO bo) throws RDPException {

		bo.setIspaging(true);
		List<CrmVO> results = crmService.findLiveness(bo);
		bo.setResults(results);
		return bo;

	}

	/**
	 * 查询黑名单信息
	 * 
	 * @return
	 * @throws RDPException
	 */
	@RequestMapping("/searchBlackList")
	@ResponseBody
	public CrmVO searchBlackList(CrmVO bo) throws RDPException {

		bo.setIspaging(true);
		List<CrmVO> results = crmService.findBlackList(bo);
		bo.setResults(results);
		return bo;

	}

	/**
	 * 查询VIP信息
	 * 
	 * @return
	 * @throws RDPException
	 */
	@RequestMapping("/searchVip")
	@ResponseBody
	public CrmVO searchVip(CrmVO bo) throws RDPException {

		bo.setIspaging(true);
		List<CrmVO> results = crmService.findVip(bo);
		bo.setResults(results);
		return bo;

	}

	/**
	 * 取消黑名单
	 * @return
	 * @throws RDPException
	 */
	@RequestMapping("/cancelBlack")
	@ResponseBody
	public String cancelBlack(HttpSession session, @RequestParam(value = "memberId", required = false)String[] memberIds) throws RDPException {
		
		crmService.cancelBlack(memberIds, UserUtil.getUserId());
		return Constants.SUCCESS;

	}


	/**
	 * 查询VIP信息
	 * 
	 * @return
	 * @throws RDPException
	 */
	@RequestMapping("/searchTotal")
	@ResponseBody
	public List<CrmVO> searchTotal(CrmVO bo) throws RDPException {
		return crmService.findCusTotal(bo);

	}
	

}
